package com.ruoyi.web.admin.shceduler;

import com.ruoyi.system.mapper.SysDeviceMapper;
import com.ruoyi.web.admin.data.DeviceSocketManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author 10100
 * @license (C) Copyright 2020-2050,  Corporation Limited.
 * @contact wang.he@cpe-smartcity.com
 * @date 2025-06-16 14:54
 * @description 设备状态检测定时任务
 */
@Component
public class DeviceConnectionStatusCheckTask {

    private final SysDeviceMapper sysDeviceMapper;

    private static final Logger log = LoggerFactory.getLogger(DeviceConnectionStatusCheckTask.class);

    @Value("${device.offline-minute:15}")
    private int minute;

    public DeviceConnectionStatusCheckTask(SysDeviceMapper sysDeviceMapper) {
        this.sysDeviceMapper = sysDeviceMapper;
    }

    @Scheduled(cron = "${task.device-connect-check:0 0/15 * * * ?}")
    @PostConstruct
    public void checkDeviceConnectionStatus() {
        sysDeviceMapper.setDeviceOffline(minute);
        log.info("设备状态检测定时任务执行完毕");
    }
}
